library(igraph)
## 
## Attaching package: 'igraph'
## The following objects are masked from 'package:stats':
## 
##     decompose, spectrum
## The following object is masked from 'package:base':
## 
##     union

1 Free scale networks (Preferential Attachment)

The command for generating a free-sacel network is barabasi.game()

# This should approximately yield the correct exponent 3
g <- barabasi.game(1000,directed = FALSE) # increase this number to have a better estimate
plot(g,vertex.label=NA)

d <- degree(g, mode="in")
plot(degree_distribution(g))

plot(degree_distribution(g),log="xy",col="sienna4",xlab="Number of connections",
     ylab="Density")
## Warning in xy.coords(x, y, xlabel, ylabel, log): 6 y values <= 0 omitted
## from logarithmic plot

boxplot(degree(g),col="snow2")

hist(d)

fit1 <- fit_power_law(d+1, 10)
fit2 <- fit_power_law(d+1, 10, implementation="R.mle")

fit1$alpha
## [1] 4.037897
stats4::coef(fit2)
##    alpha 
## 4.038365
fit1$logLik
## [1] -52.00686
stats4::logLik(fit2)
## 'log Lik.' -52.00686 (df=1)

2 The origin of architecture of (real) networks

par(mfrow=c(2,2),mar=c(0,0,0,0), oma=c(0,0,0,0))
g = watts.strogatz.game(1,20,3,0.4)
layout.old = layout.fruchterman.reingold(g)
for(i in 1:10){
     layout.new = layout.fruchterman.reingold(g,params=list(niter=10,maxdelta=2,start=layout.old))
     plot(g,layout=layout.new)
     layout.old = layout.new
     }
## Warning in layout_with_fr(structure(list(20, FALSE, c(13, 2, 9, 4, 16,
## 18, : Argument `maxdelta' is deprecated and has no effect
## Warning in layout_with_fr(structure(list(20, FALSE, c(13, 2, 9, 4, 16,
## 18, : Argument `maxdelta' is deprecated and has no effect
## Warning in layout_with_fr(structure(list(20, FALSE, c(13, 2, 9, 4, 16,
## 18, : Argument `maxdelta' is deprecated and has no effect
## Warning in layout_with_fr(structure(list(20, FALSE, c(13, 2, 9, 4, 16,
## 18, : Argument `maxdelta' is deprecated and has no effect
## Warning in layout_with_fr(structure(list(20, FALSE, c(13, 2, 9, 4, 16,
## 18, : Argument `maxdelta' is deprecated and has no effect

## Warning in layout_with_fr(structure(list(20, FALSE, c(13, 2, 9, 4, 16,
## 18, : Argument `maxdelta' is deprecated and has no effect
## Warning in layout_with_fr(structure(list(20, FALSE, c(13, 2, 9, 4, 16,
## 18, : Argument `maxdelta' is deprecated and has no effect
## Warning in layout_with_fr(structure(list(20, FALSE, c(13, 2, 9, 4, 16,
## 18, : Argument `maxdelta' is deprecated and has no effect
## Warning in layout_with_fr(structure(list(20, FALSE, c(13, 2, 9, 4, 16,
## 18, : Argument `maxdelta' is deprecated and has no effect

## Warning in layout_with_fr(structure(list(20, FALSE, c(13, 2, 9, 4, 16,
## 18, : Argument `maxdelta' is deprecated and has no effect

2.0.1 Exercises

  1. From the next networks, plot the degree distribution
g10<-barabasi.game(10,directed = FALSE)
g100<-barabasi.game(100,directed = FALSE)
g1K<-barabasi.game(1000,directed = FALSE)
g2<-random.graph.game(1000,0.20)
g3<-sample_smallworld(1,1000,p=0.2,nei=3)
g4<-make_graph("Zachary")
  1. Find the median, mean and boxplots of these distributions.
  2. Fit a power law to these distributions. Discuss your results.
  3. Fit a power law distribution to the classroom network.